package com.xthink.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xthink.common.result.AjaxResult;
import com.xthink.common.pojo.polo.WarningRecord;
import com.xthink.common.vo.pool.ListWarningRecordVo;
import com.xthink.web.mapper.WarningRecordMapper;
import com.xthink.web.service.WarningRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarningRecordServiceImpl extends ServiceImpl<WarningRecordMapper, WarningRecord> implements WarningRecordService {

    @Autowired
    private WarningRecordMapper warningRecordMapper;

    //查询流量池内告警记录
    @Override
    public AjaxResult listRecord(ListWarningRecordVo listWarningRecordVo) {
        Page<WarningRecord> page = new Page<>(listWarningRecordVo.getPage(), listWarningRecordVo.getSize());
        LambdaQueryWrapper<WarningRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WarningRecord::getPoolId, listWarningRecordVo.getPoolId());
        wrapper.like(StringUtils.isNotBlank(listWarningRecordVo.getRecord())
                , WarningRecord::getRecord
                , listWarningRecordVo.getRecord());
        wrapper.between(
                listWarningRecordVo.getStartTime() != null || listWarningRecordVo.getEndTime() != null
                , WarningRecord::getCreateTime
                , listWarningRecordVo.getStartTime()
                , listWarningRecordVo.getEndTime()
        );
        Page<WarningRecord> WarningRecord = warningRecordMapper.selectPage(page, wrapper);
        List<WarningRecord> records = WarningRecord.getRecords();
        return AjaxResult.success(records);
    }
}
